/*
-----------------------------------------------------------------------------
This source file is part of DIVA
The project of Engineering Lab, dept. of CSIE, NTNU.

Copyright (c) 2000-2006 The Software Engineering Lab, dept. of CSIE, NTNU.
-----------------------------------------------------------------------------
Filename:    DIVA_Application.h
Date:	2007/03/27
Description: 
This object initialized all required items & resource
including RenderWindow,SceneManager,OgreRoot...etc

The main resource of all main Ogre Object: 
1.OgreRoot mRoot = new Root();
2.Windows mWindow = mRoot->initialise(true);
3.SceneManager mSmg = mRoot->createSceneManager(ST_GENERIC);
4.Carama mCarama mCmr = mSmg ->createCamera("PlayerCam");
5.FrameListener = new FrameListener(<what you want>);
-----------------------------------------------------------------------------
*/

#ifndef __DIVA_Application_H__
#define __DIVA_Application_H__

#include <QWidget>
#include <QEvent>
#include <QHash>
#include "Ogre.h"//include all usable file
#include "OgreConfigFile.h"
#include "lock.h"	// for using critical section
#include <QStringList>

class QDivaAppController;

class AbstractMappingWindow;
class MappingDialog;
class DIVA_FrameListener;
class QMessageBox;

#define CAMERA_DISTANCE 5

//////////////////////////////////////////////////////////////////////////
// Sky box string constants
#define SKYBOX_MORNING "MorningSkyBox"
#define SKYBOX_STORMY "StormySkyBox"
#define SKYBOX_LOCATION "Examples/"


class DIVA_Application : public QWidget
{
	Q_OBJECT

public:
	void go();// Start the program
	void setup(); // Sets up the application - returns false if the user chooses to abandon configuration.
	void changeBackground();
	void switchFrameListener( bool turnedOn );
	MappingDialog * getMappingDialog() const;
	MappingDialog * newMappingDialog();
	QMessageBox* getMessageBox();	   // added by howway
	QDivaAppController* getController();
	Ogre::RenderWindow* getMwindow();

	// add by ParrotT
	// -----------------------------------------------------------------------------------------------------
	//

	// singleton
	static DIVA_Application *getInstance();

	//
	// -----------------------------------------------------------------------------------------------------
	//

	
protected:
	//////////////////////////////////////////////////////////////////////////
	// Members
	Ogre::Root *mRoot;  // The entry object to the OGRE system to configure the system.
	Ogre::Camera* mCamera;  // The camera to view all scene
	Ogre::SceneManager* mSceneMgr; // Manage all the entity and scenenode in the scene
	DIVA_FrameListener* mFrameListener; // To manage each frame's operation
	Ogre::RenderWindow* mWindow; // The rendering window
    Ogre::String mResourcesCfg;
    Ogre::String mPluginsCfg;
	Ogre::LogListener *_logListener;
	QStringList _skyBoxList;

	MappingDialog * _mappingDialog;
	QMessageBox* _messageBox;		// added by howway
	QDivaAppController *_controller; // added by Luke
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	// Methods
	DIVA_Application(); // Standard constructor	
	~DIVA_Application(); // Standard destructor
	bool configure(void);// Configures the application - returns false if the user chooses to abandon configuration.
	void createSceneManager(void); // Create a scene manager by mRoot
	void createCamera(std::string name); // Create a camera and set the camera position and look at direction
	void createFrameListener(void); // Create a frame listener and create a default mouse, key listener(interpreter)
	void createScene(void);
	void initSkyBox();
	void createViewports(void); // Create one viewport, entire window and alter the camera aspect ratio to match the viewport
	void setupResources(void); // Method which will define the source of resources (other than current folder)
	void createResourceListener(void); // Optional override method where you can create resource listeners (e.g. for loading screens)
	void loadResources(void);
	void updateRenderWindow();
	void createRenderWindow();
	void updateOgreStats();
	void initController(); // added by Luke for QxTesting framework on 2012/1/2
	//////////////////////////////////////////////////////////////////////////
    
	//////////////////////////////////////////////////////////////////////////
	// Qt Events
	void paintEvent (QPaintEvent* evt);
	void timerEvent (QTimerEvent* evt); // use timer to refresh window
	void resizeEvent (QResizeEvent* evt);
	void keyPressEvent(QKeyEvent* evt);
	void keyReleaseEvent(QKeyEvent* evt);
	void mousePressEvent(QMouseEvent* evt);
	void mouseReleaseEvent(QMouseEvent* evt);
	void mouseMoveEvent(QMouseEvent* evt);
	void wheelEvent(QWheelEvent* evt);
	//////////////////////////////////////////////////////////////////////////

	//
	// -----------------------------------------------------------------------------------------------------
	//
	static DIVA_Application *instance;

	// parrott:
	// 2009/12/26
	//
	// make DIVA_Application singleton

};


#endif
